<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('优惠卷列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>优惠卷类型：</p>
                            <select name="type" th:with="type=${@dict.getType('')}">
                                <option value="">所有</option>
                                <option value="0">全场赠券</option>
                                <option value="1">会员赠券</option>
                                <option value="2">购物赠券</option>
                                <option value="3">注册赠券</option>

                            </select>
                        </li>
                        <li>
                            <p>购物券名称</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="mall:coupon:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="mall:coupon:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="mall:coupon:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="mall:coupon:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('mall:coupon:edit')}]];
    var removeFlag = [[${@permission.hasPermi('mall:coupon:remove')}]];
    var prefix = ctx + "mall/coupon";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "优惠卷",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
                {
                    field: 'type',
                    title: '优惠卷类型',
                    formatter: function (value, row, index) {
                        if (row.type === 0) {
                            return "全场赠券";
                        } else if (row.type === 1) {
                            return "会员赠券";
                        } else if (row.type === 2) {
                            return "购物赠券";
                        } else {
                            return "注册赠券";
                        }

                    }
                },
                {
                    field: 'name',
                    title: '优惠券名称'
                },
                {
                    field: 'platform',
                    title: '使用平台',
                    formatter: function (value, row, index) {
                        if (row.platform === 0) {
                            return "全部";
                        } else if (row.platform === 1) {
                            return "移动";
                        } else {
                            return "PC";
                        }
                    }

                },
                {
                    field: 'count',
                    title: '数量'
                },
                {
                    field: 'note',
                    title: '备注'
                },
                {
                    field: 'amount',
                    title: '金额'
                },
                {
                    field: 'perLimit',
                    title: '每人限领张数'
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'useType',
                    title: '使用类型',
                    formatter: function (value, row, index) {
                        if (row.useType === 0) {
                            return "全场通用";
                        } else if (row.useType === 1) {
                            return "指定分类";
                        } else {
                            return "指定商品";
                        }
                    }
                },
                {
                    field: 'publishCount',
                    title: '发行数量'
                },
                {
                    field: 'useCount',
                    title: '已使用数量'
                },
                {
                    field: 'receiveCount',
                    title: '领取数量'
                },
                {
                    field: 'enableTime',
                    title: '可以领取的日期'
                },
                {
                    field: 'code',
                    title: '优惠码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="detailUrl(\'' + row.id + '\')">详情</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="AddUrl(\'' + row.id + '\')">添加优惠券</a>');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function detailUrl(id) {
        $.modal.open("优惠券明细", prefix + "/detail?id=" + id);
    }

    function AddUrl() {
        $.modal.open("添加优惠券", prefix + "/add");
    }

</script>
</body>
</html>